
var findStuInfo = toContextPath('/student/student_getInfo.action');
var findQuiz = toContextPath('/student/quiz_getAll.action');
var loginHtml = toContextPath('/StuPages/login.html');

var quizState;
$(function(){	
	initPage();
});


function initPage() {
	
	location.hash = '';
	$.getJSON(findStuInfo, function(data) {
		if (data.result && data.result.stuName){
			$('#stuName').text(data.result.stuName);
		} else {
			window.location.href = loginHtml;
		}
	});
	$.getJSON(findQuiz, function(data) {
		if (data.result && data.result.length > 0){
			$.each(data.result, function(index, quiz) {
				var item = '<tr ';
				if (quiz.state == 0) {
					quizState = "Todo";
					item += 'class="warning">';
				} else if (quiz.state == 1) {
					quizState = "Done";
					item += 'class="success">';
				}
				item = item + '<td>' + quiz.quizCreateDate + '</td>'
				+ '<td>' + quiz.quizDeadline + '</td>'
				+ '<td> <a onclick="clickA(' + quiz.state + ')">' + quiz.quizName + '</a></td>'
				+ '<td>' + quiz.teaName + '</td>'
				+ '<td ';
				if (quiz.state == 0) {
					item += 'style="color:red">' + quizState + '</td>'+ '</tr>';
				} else if (quiz.state == 1) {
					item += 'style="color:green">' + quizState + '</td>'+ '</tr>';
				}
				$('#quizList').append(item);
				
			});			
		}
	});	
}
function clickA(Sate) {
	//alert("You clicked the quiz");
	if (State == 1) {
		alert("quiz is out of date. You can't take it now!");
	} else if (State == 0) {
		alert("The quiz doesn't start now!");
	}
}

//$("#userPwd").formValidator();